home *** CD-ROM | disk | FTP | other *** search
- # Droids Cog Script
- #
- # b0_Gear.cog
- #
- # Gear Cog controlling movement of the bridge and gears assmebly.
- #
- # Desc:
- # bin 25 Small Gears
- # bin 26 Medium Gear
- # bin 27 Large Gear
- #
- # This cog is responsible for keeping track of what gears are in the Gear assembly
- # and where. It's also in charge of mocing the bridge either up or down depending on
- # how the gears are in place. There are seperate cogs for the gear pieces themselves
- # when found on the ground. After they've been placed in the gear assembly, they're
- # part of this script.
- #
- #
- # 10/23/97 [DGS] Created
- # 01/19/97 [DGS] Updated for new controls.
- # 01/21/97 [DGS] Rewrote majority of it; added new Used and Taken sections
- # ========================================================================================
-
- symbols
- message used
- message startup
- message arrived
- message user0
- message taken
- message timer
-
- ## ================Parts
- thing screw0 linkid=11
- thing screw1 linkid=11
- thing screw2 linkid=11
- thing screw3 linkid=11
- thing gear_top linkid=11
- thing gear_bot linkid=11
- thing platform linkid=3
- thing spind linkid=11
- surface Button0 linkid=2
-
- ## ==================Ghost objects
- thing l_spindle_g linkid=30
- thing r_spindle1_g linkid=31
- thing r_spindle2_g linkid=32
-
- ## ===================Ghost creation integers
- int l_spindle_i=0 linkid=11 local
- int r_spindle1_i=0 local
- int r_spindle2_i=0 local
-
- ## ====================Spin Directon integers
- flex l_spindle_d=0.0 local
- flex r_spindle1_d=0.0 local
- flex r_spindle2_d=0.0 local
- flex t_gear_d=0.0 local
-
- ## =====================templates
- template gear_large_t
- template gear_small_t
- template gear_med_t
-
- ## ======================Sectors
- sector L_Sector
- sector R_sector
-
- ## ======================Sounds
- sound gearon_snd
- sound gearongfsdfsf_snd
- sound gearoff_snd
- sound mstart_snd
- sound mstop_snd
- sound mfree_snd
- sound mstress_snd
- sound gearbog_snd
-
- ## ======================Cogs
- cog button_cog
-
- thing ghost_cam
- int l_spindle_m=0 local
- int r_spindle1_m=0 local
- int r_spindle1_m=0 local
-
-
-
- ## ======================Internal variables
- float speed=2.0 local
- int on_button=0 local
- int rotate local
- int l_spindle=0 local
- int r_spindle1=0 local
- int r_spindle2=0 local
- int timermode=0 local
- int part_id=0 local
- int g_sound=0 local
- end
- # ========================================================================================
-
- code
-
- startup:
- //
- //print("rotate it");
- //rotate = 1;
- //l_spindle_d = 1;
- //r_spindle1_d = -0.5;
- //r_spindle2_d = 0.5;
- //call rotate_gears;
-
-
- AttachThingToThing(screw0, gear_top);
- AttachThingToThing(screw1, gear_top);
- AttachThingToThing(screw2, gear_top);
- AttachThingToThing(ghost_cam, platform);
- //AttachThingToThing(screw3, screw0);
-
- MoveToFrame(platform, 1, 50);
- //RotatePivot(screw0, 1, 1);
-
- sleep(5);
- print("Gear mode:");
- printint(screw0);
- printint(screw1);
- printint(screw2);
-
- return;
-
- # ........................................................................................
- user0:
- // User0 gets called when the player hits the motor switch. See gear_activate.cog
- print("user0");
- if (rotate == 0) call start_motor;
- return;
- used:
- // Section is executed when the user uses an inventory object. Cool.
- print("USED:");
- printint(dwGetActivateBin());
- printint(getsenderid());
- if (rotate == 0)
- {
- if ( getinv(getlocalplayerthing(),dwGetActivateBin()) > 0) //if the bin has more than 0 in it;
- {
- if ((GetSenderId() == 11) || (getsenderref() == r_spindle1_i) || (getsenderref() == r_spindle2_i)) // It's used on the gear_bot
- {
- // The Gear Assembly was activated
- if (getthingsector(getlocalplayerthing()) == l_sector)
- {
- //=================== Player is on the Large gear side of the gear assembly
- print("Activated L sector");
- call handle_l;
- }
-
- if (getthingsector(getlocalplayerthing()) == r_sector)
- {
- //=================== Player is on the Small gear side of the gear assembly
- print("Activated R sector");
- call handle_r;
- }
- }
- }
- }
- return;
-
-
- taken:
- print("taken");
- printint(r_spindle1_i);
- printint(r_spindle2_i);
- printint(getsenderref());
- printint ((GetSenderId() == 11) || (getsenderref() == r_spindle1_i) || (getsenderref() == r_spindle1_i));
-
- // Taken gets called when the user attempts to take a gear from left or right of the gear assembly.
- if (rotate == 0)
- {
- if ((GetSenderId() == 11)) // if it's the gear_bot that got activated
- {
- print("Inside");
- // The Gear Assembly was activated
- if (getthingsector(getlocalplayerthing()) == l_sector)
- {
- //=================== Player is taking stuff from the left side of the gear assembly
- if (l_spindle != 0)
- {
- // inc the bin to add it back to the inv, destroy the environment one ans set l_spindle to 0.
- ChangeInv(getlocalplayerthing(), l_spindle, 1);
- destroything(l_spindle_i);
- l_spindle = 0;
- //dwSetPlayerMass(dwGetPlayerMass() + l_spindle_m);
- l_spindle_m = 0;
-
- call update_bins;
- PlaySoundThing(gearoff_snd, l_spindle_g, 1, -1, -1, 0);
- }
- else
- {
- // TELL THE PLAYER THERE'S NOTHING TO TAKE
- dwPlayCammySpeech(17305, "t9ca006.wav", 10, 0);
- timermode = 2;
- settimer(10);
- }
- }
-
- if (getthingsector(getlocalplayerthing()) == r_sector)
- {
- //=================== Player is on the Small gear side of the gear assembly
- if (r_spindle1 != 0) //if the top spindle (1) has something on it.
- {
- // inc the bin to add it back to the inv, destroy the environment one ans set r_spindle1 to 0.
- ChangeInv(getlocalplayerthing(), r_spindle1, 1);
- //releasething(r_spindle1_i);
- destroything(r_spindle1_i);
- r_spindle1 = 0;
- //dwSetPlayerMass(dwGetPlayerMass() + r_spindle1_m);
- r_spindle1_m - 0;
-
- call update_bins;
- PlaySoundThing(gearoff_snd, r_spindle1_g, 1, -1, -1, 0);
- }
- else if (r_spindle2 != 0) //if the bottom spindle (2) has something on it
- {
- // inc the bin to add it back to the inv, destroy the environment one ans set r_spindle2 to 0.
- ChangeInv(getlocalplayerthing(), r_spindle2, 1);
- //releasething(r_spindle2_i);
- destroything(r_spindle2_i);
- r_spindle2 = 0;
- //dwSetPlayerMass(dwGetPlayerMass() + r_spindle2_m);
- r_spindle2_m - 0;
- PlaySoundThing(gearoff_snd, r_spindle1_g, 1, -1, -1, 0);
- call update_bins;
- }
- else //else there's nothing on this side. Both spindles are empty.
- {
- dwPlayCammySpeech(17305, "t9ca006.wav", 10, 0); //There's nothing to take
- timermode = 2;
- settimer(10);
- }
- }
- }
- }
- return;
- grind_gears:
- // Controls causing the grind sound .
- garbage = PlaySoundThing(gearbog_snd, gear_bot, 1, -1, -1, 0);
- dwPlayCammySpeech(17313, "t9ca014.wav", 10, 0);
- timermode = 3;
- settimer(1);
- return;
-
- start_motor:
- if ( (l_spindle == 27) && (r_spindle1 == 25) && (r_spindle2 == 25) ) // if all the grears are in place
- {
- r_spindle2_d = 0;
- r_spindle1_d = 0;
- l_spindle_d = 0;
- //
- call grind_gears;
- }
- else // Else set up the way it's all gonna spin
- { // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Set motion/direction
- t_gear_d = 0; //Assume that if the top gear is going to move, the below lines will set it that way.
- // These if/else statements set up the speeds and directions for the gears on the 3 spindles.
- if (l_spindle == 27)//if it's the large gear in the left spindle
- {
- l_spindle_d = -1; //set the direction to -0.5
- t_gear_d = -0.5; //set the top gears direction.
- }
- else l_spindle_d = 0;// else set the gears speed to 0, since md. and sm. gears don't touch the upper and lower gears when they're on the left.
-
- if (r_spindle2 == 25)
- {
- r_spindle2_d = 0.5;// if the sm. gear is on the lower spindle then set its speed and dirction
- }
- else r_spindle2_d = 0;// else set the gears speed to 0, since the sm. gear is the only one that can go on the lower spindle
-
- if ((r_spindle1 == 25) && (r_spindle2 == 25)) //if the upper gear is there and the lower gear is there
- {
- r_spindle1_d = -0.5;//
- t_gear_d = 0.5; //set the top gears direction to move the platform up.
- }
- else if ((r_spindle1 == 25) && (l_spindle == 27)) r_spindle1_d = 0.5;// if the lower gear and the lg. gear is there then set the speed.
- else r_spindle1_d = 0;//else it's not going to spin when the switch is pulled.
-
-
- printint(r_spindle2);
- printflex(r_spindle2_d);
-
- if (t_gear_d > 0) //if the top gear is connected to the lower gear and spinning up
- {
- if (GetCurFrame(platform) > 0) //if the platform's not already at the top
- {
- MoveToFrame(platform, GetCurFrame(platform)-1, speed); //move the platform up
- dwPlayCammySpeech(17302, "t9ca004.wav", 10, 0);
- garbage = PlaySoundThing(mstart_snd, gear_bot, 1, -1, -1, 0);
- g_sound = PlaySoundThing(mstress_snd, gear_bot, 1, -1, -1, 1);
-
- call rotate_gears;
- timermode = 4;
- settimer(2);
-
-
- }
- else // else make the grinding sound
- {
- call grind_gears;
- }
- }
- else if (t_gear_d < 0) //else if the top gear is connected to the lower gear and spinning down
- {
- if (GetCurFrame(platform) < 2) //if the platform's not already at the bottom
- {
- MoveToFrame(platform, GetCurFrame(platform)+1, speed); //move the platform down
- dwPlayCammySpeech(17302, "t9ca004.wav", 10, 0);
- garbage = PlaySoundThing(mstart_snd, gear_bot, 1, -1, -1, 0);
- g_sound = PlaySoundThing(mstress_snd, gear_bot, 1, -1, -1, 1);
-
- call rotate_gears;
- timermode = 4;
- settimer(2);
- }
- else // else make the grinding sound
- {
- call grind_gears;
- }
- }
- else // else top Gear's not connected; spin the bottom
- {
- //SET THE TIME
- timermode = 1;// Timermode tells the timer what to do when it's called.
- settimer(10);
- dwPlayCammySpeech(17315, "t9ca016.wav", 10, 0);
- garbage = PlaySoundThing(mstart_snd, gear_bot, 1, -1, -1, 0);
- g_sound = PlaySoundThing(mfree_snd, gear_bot, 1, -1, -1, 1);
-
- call rotate_gears;
- }
- }
- return;
-
- rotate_gears:
- //This routine starts the gears a spinnin'. After they're goin', continue_gears is used to keep the thing spinning.
- rotate = 1;
- //RotatePivot(screw0, 1, 1);
- RotatePivot(gear_bot, 1, 0.5);
- print("Rotates!");
- printint(l_spindle_d);
- if (!(l_spindle_d == 0.0)) RotatePivot(l_spindle_i, 1, l_spindle_d);
- if (!(r_spindle1_d == 0.0)) RotatePivot(r_spindle1_i, 1, r_spindle1_d);
- if (!(r_spindle2_d == 0.0)) RotatePivot(r_spindle2_i, 1, r_spindle2_d);
- if (!(t_gear_d == 0.0)) RotatePivot(gear_top, 1, t_gear_d);
- return;
-
-
- continue_gears:
- printint(getsenderid());
- if (!(l_spindle_d == 0.0)) RotatePivot(l_spindle_i, 1, l_spindle_d);
- if (!(r_spindle1_d == 0.0)) RotatePivot(r_spindle1_i, 1, r_spindle1_d);
- if (!(r_spindle2_d == 0.0)) RotatePivot(r_spindle2_i, 1, r_spindle2_d);
- if (!(t_gear_d == 0.0)) RotatePivot(gear_top, 1, t_gear_d);
- if (getsenderid() == 11) RotatePivot(gear_bot, 1, 0.5);
- return;
-
- stop_gears:
- //this routine stops all motion of the gears when it's called. Hopefully. Otherwise, well. Otherwise.
- stopthing(r_spindle1_i);
- stopthing(l_spindle_i);
- stopthing(r_spindle2_i);
- stopthing(gear_top);
- stopthing(gear_bot);
- rotate = 0;
- sendmessage(button_cog, user0);
- if (g_sound > 0)
- {
- stopsound(g_sound,0.1);
- garbage = PlaySoundThing(mstop_snd, gear_bot, 1, -1, -1, 0);
- }
- timermode = 5;
- settimer(1);
- return;
-
- handle_l:
- // handle_l is used to put gears on the left side of the assembly. handle_r is for the right. Taken handles removing gears.
- print("handle_l:");
- if (l_spindle == 0) //if the spindle is empty
- {
- //============ Add whatever you gots to the spindle
- if ((dwGetActivateBin() > 24) && (dwGetActivateBin() < 94)) // if it's one of the gears that's being used
- {
- // 3 things happen here. First the variable l_spindle is set to the gear that's going to go on the spindle.
- // The bin number from the gear is used to represent what gear is on the spindle. if l_spindle is set to 0, then
- // there should be no gear on the spindle. If it's a non-zero number, it represents the present gear's bin number.
- l_spindle = dwGetActivateBin();
-
- // Next l_spindle is queried to figure out what gear is going to be created. Then it's created
- if (l_spindle == 25)
- {
- print("gear small");
- l_spindle_i = creatething(gear_small_t, l_spindle_g);
- l_spindle_m = 160;
- //dwSetPlayerMass(dwGetPlayerMass() - l_spindle_m);
- }
- else if (l_spindle == 26)
- {
- l_spindle_i = creatething(gear_med_t, l_spindle_g);
- l_spindle_m = 200;
- //dwSetPlayerMass(dwGetPlayerMass() - l_spindle_m);
- print("gear med");
- }
- else if (l_spindle == 27)
- {
- l_spindle_i = creatething(gear_large_t, l_spindle_g);
- l_spindle_m = 260;
- //dwSetPlayerMass(dwGetPlayerMass() - l_spindle_m);
- print("gear large");
- }
- // finally we decrement the bin that was activated.
- PlaySoundThing(gearon_snd, l_spindle_g, 1, -1, -1, 0);
- ChangeInv(getlocalplayerthing(), l_spindle, -1);
- call update_bins;
- }
- }
- else
- {
- // TELL THE PLAYER THERE'S SOMETHING ON THE SPINDLE ALREADY
- dwPlayCammySpeech(17304, "t9ca005.wav", 10, 0);
- timermode = 2;
- settimer(10);
- }
-
- return;
-
- handle_r:
- // handle_r controls putting gears on the right side of the assemebly. handle_l is the left side. Taken controls removing gears for both l and r.
- print("handle_r:");
- if (r_spindle2 > 0) //if the bottom spindle has something on it
- {
- // check the top spindle
- if (r_spindle1 > 0) //if the top spindle has something on it
- {
- // There's gears already here
- dwPlayCammySpeech(17304, "t9ca005.wav", 10, 0);
-
- timermode = 2;
- settimer(10);
- }
- else //else the upper spindle is empty
- {
- //============ This section controls the upper spindle only (r_spindle1).
-
- if (dwGetActivateBin() == 25) // if it's the small gear
- {
- // check the comments from handle_l for info on the creation process of a gear. Then check with Doug
- r_spindle1 = dwGetActivateBin();
- r_spindle1_i = creatething(gear_small_t, r_spindle1_g);
- //capturething(r_spindle1_i);
- r_spindle1_m = 160;
- //dwSetPlayerMass(dwGetPlayerMass() - r_spindle1_m);
-
- ChangeInv(getlocalplayerthing(), r_spindle1, -1);
- PlaySoundThing(gearon_snd, r_spindle1_g, 1, -1, -1, 0);
-
- call update_bins;
- }
- else //Else it's not the small gear
- {
- if ((dwGetActivateBin() > 25) && (dwGetActivatebin() < 28)) // If it's the med or large gear
- {
- dwPlayCammySpeech(17311, "t9ca012.wav", 10, 0);
- timermode = 2;
- settimer(10);
- }
- }
-
- }
- }
- else //else the bottom spindle is empty
- {
- if (dwGetActivateBin() == 25) // if it's the small gear
- {
- // check the comments from handle_l for info on the creation process of a gear. Then check with Doug
- r_spindle2 = dwGetActivateBin();
- r_spindle2_i = creatething(gear_small_t, r_spindle2_g);
- //capturething(r_spindle2_i);
- r_spindle2_m = 160;
- //dwSetPlayerMass(dwGetPlayerMass() - r_spindle2_m);
- ChangeInv(getlocalplayerthing(), r_spindle2, -1);
- PlaySoundThing(gearon_snd, r_spindle2_g, 1, -1, -1, 0);
- call update_bins;
- }
- else //Else it's not the small gear
- {
- if ((dwGetActivateBin() > 25) && (dwGetActivatebin() < 28)) // If it's the med or large gear
- {
- dwPlayCammySpeech(17311, "t9ca012.wav", 10, 0);
- timermode = 2;
- settimer(10);
- }
- }
-
- }
- return;
- # ............................................... .........................................
- arrived:
- if ((GetSenderId() != 3) && (rotate == 1))
- {
- call continue_gears;
- }
- if (GetSenderId() == 3)
- {
- call stop_gears;
- rotate = 0;
- }
- return;
-
- timer:
- if (timermode == 1) //Will turn off the gears.
- {
- call stop_gears;
- rotate = 0;
- sendmessage(button_cog, user0);
- }
- else if (timermode == 2) //will clear Cammy's text
- {
- }
- else if (timermode == 3) //will clear Cammy's text and set the switch back to 0;
- {
- timermode = 2;
- settimer(9);
- sendmessage(button_cog, user0);
- }
- else if (timermode == 4) //ext. camera
- {
- dwFreezePlayer();
- SetCameraFocus(0, ghost_cam);
- SetCurrentCamera(0);
- }
- else if (timermode == 5) //Reset camera to player.
- {
- SetCurrentCamera(7);
- dwunfreezeplayer();
- }
- return;
-
- update_bins:
- // this is a utility routine used to turn on and off availability of items. Just until Jon adds it into DW for reals.
- if ( getinv(getlocalplayerthing(),25) > 0) SetInvAvailable(getlocalplayerthing(), 25, 1); //if the sm. bin has more than 0 turn on the inv icon;
- else SetInvAvailable(getlocalplayerthing(), 25, 0); // else turn it off;
-
- if ( getinv(getlocalplayerthing(),26) > 0) SetInvAvailable(getlocalplayerthing(), 26, 1); //if the md. bin has more than 0 turn on the inv icon;
- else SetInvAvailable(getlocalplayerthing(), 26, 0); // else turn it off;
-
- if ( getinv(getlocalplayerthing(),27) > 0) SetInvAvailable(getlocalplayerthing(), 27, 1); //if the lg. bin has more than 0 turn on the inv icon;
- else SetInvAvailable(getlocalplayerthing(), 27, 0); // else turn it off;
- return;
- end
-
-